<html><head><title>RAD Module reference</title>
<link rel=stylesheet Type=text/css href='../../../../doc/bmxstyle.css'>
</head><body>
<table width=100% cellspacing=0><tr align=center><td class=small>&nbsp;</td>
<td class=small width=1%><b>jmd.rad:</b></td>
<td class=small width=1%><a href=#functions class=small>Functions</a></td>
<td class=small width=1%><a href=#modinfo class=small>Modinfo</a></td>
<td class=small width=1%><a href='../../../../mod/jmd.mod/rad.mod/rad.bmx' class=small>Source</a></td>
<td class=small>&nbsp;</td></tr></table>
<h1>RAD Module</h1>
This modules provides some simple implementations of some of my old favorite
3DRAD convenience functions.
<h2><a name=functions></a>Functions Summary</h2><table class=doc width=100%>
<tr><td class=docleft width=1%><a href=#between>between</a></td><td class=docright>
See if a value is between a range.
</td></tr>
<tr><td class=docleft width=1%><a href=#betweenFloat>betweenFloat</a></td><td class=docright>
See if a value is between a range.
</td></tr>
<tr><td class=docleft width=1%><a href=#interpolate>interpolate</a></td><td class=docright>
Linear interpolation.
</td></tr>
<tr><td class=docleft width=1%><a href=#interpolateFloat>interpolateFloat</a></td><td class=docright>
Linear interpolation.
</td></tr>
<tr><td class=docleft width=1%><a href=#limit>limit</a></td><td class=docright>
Limit value.
</td></tr>
<tr><td class=docleft width=1%><a href=#limitFloat>limitFloat</a></td><td class=docright>
Limit value.
</td></tr>
<tr><td class=docleft width=1%><a href=#Oscillate>Oscillate</a></td><td class=docright>
Return a sinus value.
</td></tr>
<tr><td class=docleft width=1%><a href=#Rebound>Rebound</a></td><td class=docright>
rebound a value with elasticity.
</td></tr>
<tr><td class=docleft width=1%><a href=#wrap>wrap</a></td><td class=docright>
wrap a value.
</td></tr>
<tr><td class=docleft width=1%><a href=#wrapFloat>wrapFloat</a></td><td class=docright>
wrap a value.
</td></tr>
</table>
<h2
 id=functionsdet>Functions
</h2>
<table class=doc width=100% cellspacing=3 id=between>
<tr><td class=doctop colspan=2>Function between:Int(value:Int,vMin:Int,vMax:Int)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright><b>True</b> or <b>False</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>See if a value is between a range.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Return <b>true</b> if <b>value</b> is between <b>vMin</b> and <b>vMax</b>, otherwise return <b>false</b>
<p>
Example:
<pre>
if between(this,1,100) then print "this is between 1 and 100!"
</pre>
<p>
see also: <a href=#betweenFloat>betweenFloat</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=betweenFloat>
<tr><td class=doctop colspan=2>Function betweenFloat:Int(value:Float,vMin:Float,vMax:Float)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright><b>True</b> or <b>False</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>See if a value is between a range.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Return <b>true</b> if <b>value</b> is between <b>vMin</b> and <b>vMax</b>, otherwise return <b>false</b>
<p>
Example:
<pre>
if between(this,1,100) then print "this is between 1 and 100!"
</pre>
<p>
see also: <a href=#between>between</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=interpolate>
<tr><td class=doctop colspan=2>Function interpolate:Int(value:Int,vMin:Int,vMax:Int,retMin:Int,retMax:Int)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>an integer value between <b>retMin</b> and <b>retMax</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>Linear interpolation.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Interpolate <b>value</b> (which is between <b>vMin</b> and <b>vMax</b>) to be in the range of <b>retMin</b> and <b>retMax</b>.
<p>
Example:
<pre>
this:int = interpolate(10,1,10,1,100) ' results in 100 being returned
</pre>
<p>
see also: <a href=#interpolateFloat>interpolateFloat</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=interpolateFloat>
<tr><td class=doctop colspan=2>Function interpolateFloat:Float(value:Float,vMin:Float,vMax:Float,retMin:Float,retMax:Float)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>an floating point value between <b>retMin</b> and <b>retMax</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>Linear interpolation.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Interpolate <b>value</b> (which is between <b>vMin</b> and <b>vMax</b>) to be in the range of <b>retMin</b> and <b>retMax</b>.
<p>
Example:
<pre>
this:Float = interpolateFloat(5.0,1.0,10.0,1.0,100.0) ' results in 50.0 being returned
</pre>
<p>
see also: <a href=#interpolate>interpolate</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=limit>
<tr><td class=doctop colspan=2>Function limit:Int(value:Int,vMin:Int,vMax:Int)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>an integer clamped between <b>vMin</b> and <b>vMax</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>Limit value.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>If <b>value</b> is between <b>vMin</b> and <b>vMax</b>, then <b>value</b> is returned.
If <b>value</b> is less than <b>vMin</b>, then <b>vMin</b> is returned.
If <b>value</b> is greater than <b>vMax</b>, then <b>vMax</b> is returned.
<p>
Example:
<pre>
this:int=limit(this,1,100) 'clamps this to be between 1 and 100
</pre>
<p>
see also: <a href=#limitFloat>limitFloat</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=limitFloat>
<tr><td class=doctop colspan=2>Function limitFloat:Float(value:Float,vMin:Float,vMax:Float)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>a float clamped between <b>vMin</b> And <b>vMax</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>Limit value.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>If <b>value</b> is between <b>vMin</b> And <b>vMax</b>, Then <b>value</b> is returned.
If <b>value</b> is less than <b>vMin</b>, Then <b>vMin</b> is returned.
If <b>value</b> is greater than <b>vMax</b>, Then <b>vMax</b> is returned.
<p>
Example:
<pre>
this:Float=limitFloat(this,1,100) 'clamps this to be between 1 and 100
</pre>
<p>
see also: <a href=#limit>limit</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=Oscillate>
<tr><td class=doctop colspan=2>Function Oscillate:Float(retMin:Float,retMax:Float,speed:Float,offset:Float)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>a <b>Float</b> sinus value.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>Return a sinus value.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>The <b>retMin</b> parameter is the minim sinus value
The <b>retMax</b> parameter is the maximum sinus value
The <b>speed</b>  parameter is the amount of time in milliseconds for one cycle to complete
The <b>offset</b> parameter is  an offset, in degrees, added to the sinus value
<p>
Returns a sinus wave between vMin and vMax at the specified frequency. The <b>speed</b> parameter
is the duration in milliseconds to complete one cycle. Hertz can easily be used instead with a
simple formulat of: milli:=1000/hertz, as shown in the next example:
<pre>
hz:int=1000/15 '15hz
thisVar:float = Oscillate(0,100,hz,0) '15hz oscillation
</pre>
<p>
Below is a more complete example of how <a href=#Oscillate>Oscillate</a>() and its parameters can be used.</td></tr>
<tr><td class=docleft width=1%><a href=Oscillate.bmx class=small>Example</a></td><td class=docright><pre>Import jmd.rad

Graphics 640,480

While Not KeyDown(KEY_ESCAPE)
	Cls
	Local numSpheres:Int=30
	For Local i:Int = 0 To numSpheres
	SetColor(i*8,128-i*7,255-i*7)
	DrawOval Oscillate(0,600,2000,i*(360/numSpheres)),i*20,20,20
	Next
	Flip

Wend</pre></td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=Rebound>
<tr><td class=doctop colspan=2>Function Rebound:Float(value:Float,elasticity:Float,deadband:Float=0.1)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>an inverted and dampened <b>Float</b> value.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>rebound a value with elasticity.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Rebound a value with elasticity. The optional <b>deadband</b> parameter will force the returned
value to 0 if within the deadband. See example of bouncing ball below:
<p>
Note: elasticity values should normally be below 1.0, but values above 1.0 become "super-elastic"
and rebound with more force than the initial value.</td></tr>
<tr><td class=docleft width=1%><a href=Rebound.bmx class=small>Example</a></td><td class=docright><pre>Import jmd.rad

Local velY:Float = 0.001
Local gravityForce:Float = -0.5
Local posY:Float = 0
Local ballDiameter:Int = 50

Graphics 640,480

While Not KeyDown(KEY_ESCAPE)
	
	
	If velY<>0
	'calculate gravity forces
	velY:- gravityForce
	'add acceleration to postion
	posY:+ velY
	EndIf
	
	'Rebound!
	If posY>GraphicsHeight()-ballDiameter
		velY=Rebound(velY,0.75,0.1)
	EndIf
	
	'Reset?
	If KeyHit(KEY_R)
		posY=0
		velY=0.001
	EndIf
	
	'Draw it
	Cls
	DrawText "Press R to reset",10,10
	DrawOval GraphicsWidth()/2,posY,ballDiameter,ballDiameter
	Flip

Wend</pre></td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=wrap>
<tr><td class=doctop colspan=2>Function wrap:Int(value:Int,retMin:Int,retMax:Int)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>an <b>Int</b> between <b>vMin</b> and <b>vMax</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>wrap a value.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Wrap <b>value</b> around <b>vMin</b> and <b>vMax</b> and return that value.
<p>
example:
<pre>
this:int = wrap(15,1,10) 'results in this=5
</pre>
<p>
see also: <a href=#wrapFloat>wrapFloat</a>()</td></tr>
</table>
<br>
<table class=doc width=100% cellspacing=3 id=wrapFloat>
<tr><td class=doctop colspan=2>Function wrapFloat:Float(value:Int,retMin:Float,retMax:Float)</td></tr>
<tr><td class=docleft width=1%>Returns</td><td class=docright>a <b>Float</b> between <b>vMin</b> and <b>vMax</b>.</td></tr>
<tr><td class=docleft width=1%>Description</td><td class=docright>wrap a value.</td></tr>
<tr><td class=docleft width=1%>Information</td><td class=docright>Wrap <b>value</b> around <b>vMin</b> and <b>vMax</b> and return that value.
<p>
example:
<pre>
this:Float = wrapFloat(15.0,1.0,10.0) 'results in this=5
</pre>
<p>
see also: <a href=#wrap>wrap</a>()</td></tr>
</table>
<br>
<h2 id=modinfo>Module Information</h2>
<table width=100%>
<tr><th width=1%>Version</th><td>1.0</td></tr>
<tr><th width=1%>Author</th><td>Jonathan Decker</td></tr>
<tr><th width=1%>License</th><td>GNU GPL v3</td></tr>
<tr><th width=1%>SVN</th><td>http://blitzmax-rad-module.googlecode.com/svn/trunk/</td></tr>
</body></html>
